package com.ruoyi.project.naming.namingzi.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.naming.namingzi.domain.NamingZi;
import com.ruoyi.project.naming.namingzi.service.INamingZiService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 起名用字Controller
 *
 * @author shixiangwen
 * @date 2021-11-29
 */
@Controller
@RequestMapping("/naming/namingzi")
public class NamingZiController extends BaseController {

    private String prefix = "naming/namingzi";

    @Autowired
    private INamingZiService namingZiService;

    @RequiresPermissions("naming:namingzi:view")
    @GetMapping()
    public String namingzi() {
        return prefix + "/namingzi";
    }

    /**
     * 查询起名用字列表
     */
    @RequiresPermissions("naming:namingzi:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(NamingZi namingZi) {
        startPage();
        List<NamingZi> list = namingZiService.selectNamingZiList(namingZi);
        return getDataTable(list);
    }

    /**
     * 导出起名用字列表
     */
    @RequiresPermissions("naming:namingzi:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(NamingZi namingZi) {
        List<NamingZi> list = namingZiService.selectNamingZiList(namingZi);
        ExcelUtil<NamingZi> util = new ExcelUtil<NamingZi>(NamingZi.class);
        return util.exportExcel(list, "namingzi");
    }

    /**
     * 新增起名用字
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存起名用字
     */
    @RequiresPermissions("naming:namingzi:add")
    @Log(title = "起名用字", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(NamingZi namingZi) {
        return toAjax(namingZiService.insertNamingZi(namingZi));
    }

    /**
     * 修改起名用字
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        NamingZi namingZi = namingZiService.selectNamingZiById(id);
        mmap.put("namingZi", namingZi);
        return prefix + "/edit";
    }

    /**
     * 修改保存起名用字
     */
    @RequiresPermissions("naming:namingzi:edit")
    @Log(title = "起名用字", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(NamingZi namingZi) {
        return toAjax(namingZiService.updateNamingZi(namingZi));
    }

    /**
     * 删除起名用字
     */
    @RequiresPermissions("naming:namingzi:remove")
    @Log(title = "起名用字", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(namingZiService.deleteNamingZiByIds(ids));
    }


    @RequiresPermissions("naming:namingzi:view")
    @GetMapping("/test")
    public String test() {
        return prefix + "/test";
    }

}
